package com.cx.repository;

import com.cx.domain.Discuss;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import org.springframework.data.domain.Pageable;

import java.util.List;

//快捷键Ctrl+o可以查看已经有的方法
public interface DiscussRepository extends JpaRepository<Discuss, Integer> {

    List<Discuss> findByAuthorNotNull();

    @Query("SELECT c from  t_comment c where c.aId=?1")
    public List<Discuss> getDiscussPaged(Integer aid, Pageable pageable);

    @Query(value = "SELECT c from  t_comment c where c.aId=?1", nativeQuery = true)
    public List<Discuss> getDiscussPaged2(Integer aid, Pageable pageable);


    @Transactional
    @Modifying
    @Query("UPDATE t_comment c SET c.author = ?1 WHERE c.id = ?2")
    public int updateDiscuss(String author, Integer id);

    @Transactional
    @Modifying
    @Query("DELETE t_comment c WHERE c.id = ?1")
    public int deleteDiscuss(Integer id);

}
